#region Using directives
using System;

using WP.MF.DataAccess;
using WP.MF.BusinessRule;
using WP.MF.DataEntity;
using WP.DB;
using WP.Commons;
#endregion


namespace WP.MF.BusinessLogical
{
	/// <summary>
	/// Summary description for MPeriodBLL.
	/// </summary>
	public class MPeriodBLL
	{
		MPeriodDAL mPeriodDAL=new MPeriodDAL();
		public MPeriodBLL()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		#region GetPeriodByModuleName: GetPeriod into By ModuleName
		public MPeriodDEL GetPeriodByModuleName(SystemModules systemModules)
		{
			DBAccess dBAccess=new DBAccess();

			return mPeriodDAL.GetPeriodByModuleName(dBAccess,systemModules);

		}	
		#endregion

		#region InsertMPeriod: GetPeriod into By ModuleName
		public bool InsertMPeriod(MPeriodDEL mPeriodDEL)
		{
			DBAccess dBAccess=null;
			MPeriodDAL mPeriodDAL=new MPeriodDAL();
			MPeriodBRL mPeriodBRL=new MPeriodBRL();
			
			if(!mPeriodBRL.InsertMPeriodValid(mPeriodDEL))
			{
				return false;
			}
			
			try
			{
				dBAccess=new DBAccess(false,true);

				mPeriodDAL.DeleteMPeriod(dBAccess,mPeriodDEL.Tables[MPeriodDEL.TABLENAME_MPERIOD].Rows[0][MPeriodDEL.MODULENAME].ToString());	

				mPeriodDAL.InsertMPeriod(dBAccess,mPeriodDEL);

				mPeriodDAL.UpdateMPeriodForSepcialModule(dBAccess,mPeriodDEL);

				dBAccess.CommitTranAndCloseCon();
				return true;
			}
			catch(Exception e)
			{
				dBAccess.RollbackTranAndClose();
				throw new BaseException(e.Message);
			}
		}	
		#endregion
	}
}
